//
//  CustomButton.m
//  Dear
//
//  Created by 陈俊俊 on 15/9/2.
//  Copyright (c) 2015年 陈俊俊. All rights reserved.
//

#import "CustomButton.h"
#define ImageWidth 20
#define ImageHeight 30

@interface CustomButton ()
{
    NSString *_imageName;
    NSString *_title;

}
@end

@implementation CustomButton
- (instancetype)initWithFrame:(CGRect)frame withTitle:(NSString *)title withImage:(NSString *)imageName{
    self = [super initWithFrame:frame];
    if (self) {
        _imageName = imageName;
        _title = title;
        [self bulidLayout];
    }
    return  self;
}
- (void)bulidLayout{
    UIImageView *imageView = [[UIImageView alloc]initWithFrame:CGRectMake((self.frame.size.width -ImageWidth)/2, 30, ImageWidth, ImageHeight)];
    if ([_imageName isEqualToString:@"dear_tab_found_four"]) {
        imageView.frame = CGRectMake((self.frame.size.width -30)/2, 30, 30, 40);
    }
    imageView.image = ImageName(_imageName);
    imageView.contentMode = UIViewContentModeScaleAspectFit;
    [self addSubview:imageView];
    UILabel *titleLabel = [[UILabel alloc]initWithFrame:CGRectMake(0, CGRectGetMaxY(imageView.frame)+5, self.frame.size.width, 20)];
    titleLabel.font = FontSize(12);
    titleLabel.text = _title;
    titleLabel.textColor = [UIColor blackColor];
    titleLabel.textAlignment = NSTextAlignmentCenter;
    [self addSubview:titleLabel];
}



@end
